'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    errorHandler = require('./errors.server.controller'),
    Groups = mongoose.model('GroupManagement'),
    _ = require('lodash');


/**
 * Create a Group management
 */
exports.create = function(req, res) {
	debugger;
    var group = new Groups(req.body);
    group.isActive= true;
  /*  group.title = req.title;*/
    group.save(function(err) {
        if (err) {
            return res.status(400).send({
                message: errorHandler.getErrorMessage(err)
            });
        } else {
            res.json(group);
        }
    });
};

/**
 * Show the current Group management
 */
exports.read = function(req, res) {

};

/**
 * Update a Group management
 */
exports.update = function(req, res) {

};

/**
 * Delete an Group management
 */
exports.delete = function(req, res) {

};

/**
 * List of Group managements
 */
exports.list = function(req, res) {
    Groups.find({}).sort('title').exec(function(err, sessions) {
        if (err) {
            return res.status(400).send({
                message: errorHandler.getErrorMessage(err)
            });
        } else {
            res.json(sessions);
        }
    });
};